#include "container.h"
#include "container_config.h"
#include "toml/get.hpp"
#include "toml/parser.hpp"
#include <cstdlib>
#include <gflags/gflags.h>
#include <toml.hpp>
#include "fmt/color.h"

DEFINE_string(config, "./config.toml",
              "config file location. example: ./config.toml");

ContainerConfig load_config(std::string_view file_path) {
  auto config_data = toml::parse(file_path.data());

  ContainerConfig conf {
    .command = toml::find<std::vector<std::string>>(config_data, "command"),
    .memory_limit = toml::find<std::string>(config_data, "memory_limit"),
    .cpu_limit = toml::find<size_t>(config_data, "cpu_limit"),
    .base_image = toml::find<std::string>(config_data, "base_image"),
    .pids_limit = toml::find<size_t>(config_data, "pids_limit")
  };

  fmt::print(fmt::fg(fmt::color::green), "load config success!\n");

  return conf;
}

int main(int argc, char **argv) {
  gflags::ParseCommandLineFlags(&argc, &argv, true);

  auto conf = load_config(FLAGS_config);
  Container c(conf);
  c.start();


  return 0;
}